package cn.stylefeng.guns.modular.app;

import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * App下载
 * @author zhucx
 *
 */
@Controller
@RequestMapping("/appDownload")
public class appDownloadController {
    
    /**
     * 下载APP
     * @author zhucx
     * @throws ServletException , IOException
     */
	@RequestMapping("download")
     public void downLoad(HttpServletResponse response) {
         String path = "assets/appfile/jilu.apk";
         try {
             InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
             OutputStream  outputStream = response.getOutputStream();
             //设置下载的文件类型
             response.setContentType("application/vnd.android.package-archive;charset=utf-8");
             //设置下载文件名
             response.setHeader("Content-Disposition", "attachment;filename=" + new String(("jilu" + ".apk").getBytes(), "iso-8859-1"));
             IOUtils.copy(inputStream, outputStream);
             outputStream.flush();
             inputStream.close();
             outputStream.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
    
    /**
     * 下载工牌连接工具app
     * @author zhucx
     * @throws ServletException , IOException
     */
	@RequestMapping("download_bleBadgeTool")
     public void download_bleBadgeTool(HttpServletResponse response) {
         String path = "assets/appfile/BleBadgeTool-v1.1.1.apk";
         try {
             InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
             OutputStream  outputStream = response.getOutputStream();
             //设置下载的文件类型
             response.setContentType("application/vnd.android.package-archive;charset=utf-8");
             //设置下载文件名
             response.setHeader("Content-Disposition", "attachment;filename=" + new String(("BleBadgeTool-v1.1.1" + ".apk").getBytes(), "iso-8859-1"));
             IOUtils.copy(inputStream, outputStream);
             outputStream.flush();
             inputStream.close();
             outputStream.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
    
}
